//
//  TSWorkController.m
//  chart
//
//  Created by 曾斌 on 16/5/1.
//  Copyright (c) 2016年 xu. All rights reserved.
//

#import "TSWorkController.h"
#import "TSMsgTabBarController.h"
#import "TSCreateTaskTabBarController.h"
#import "TSReceiveTabBarController.h"
#import "TSSuperviseTabBarController.h"
#import "TSFinishTabBarController.h"
#import "TSPraiseTabBarController.H"
#define SPACING      1  //水平，垂直间隙
#define COLUM        4   //几列
#define TOP_IMAGE_HEIGHT   150   //顶部图片高度
#define IMAGE_TOP_BOTTOM_MARGINT   10
#define IMAGE_LEFT_RIGHT_MARGINT   15

@implementation TSWorkController
{
    UIImageView * topImage;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    self.title = @"工作";
    [self initUI];
}

-(void)initUI{
    [self addTopImage];
    [self addImageGrid];
}

-(void)addImageGrid{
    int width = (currentDeviceWidth -3*SPACING)/COLUM;
    
    for(int i=0;i<6;i++){
        UIView *layout = [[UIView alloc] init];
        UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"work_icon_%zd", i+1]]];
        int y = i/4*(SPACING+width)+TOP_IMAGE_HEIGHT;
        int x = i%4*(SPACING+width);
        layout.frame =CGRectMake(x, y, width, width);
        img.frame = CGRectMake(IMAGE_LEFT_RIGHT_MARGINT,IMAGE_TOP_BOTTOM_MARGINT, width-2*IMAGE_LEFT_RIGHT_MARGINT, width-2*IMAGE_TOP_BOTTOM_MARGINT);
        [layout addSubview:img];
        layout.backgroundColor=[UIColor whiteColor];
        [layout setUserInteractionEnabled:YES];
        [layout setTag:i];
        UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(workClick:)];
        [layout addGestureRecognizer:singleTap1];
        [self.view addSubview:layout];
    }
}

-(void)workClick:(UITapGestureRecognizer *)tap{
    UIView * sender = tap.view;
    if(sender.tag == 0){
        //任务发起
        TSCreateTaskTabBarController * creat = [[TSCreateTaskTabBarController alloc] init];
        [self presentViewController:creat animated:YES completion:nil];
    }else if(sender.tag == 1){
        //任务管理
        TSReceiveTabBarController * creat = [[TSReceiveTabBarController alloc] init];
        [self presentViewController:creat animated:YES completion:nil];
    }else if(sender.tag == 2){
        //任务监督
        TSSuperviseTabBarController * creat = [[TSSuperviseTabBarController alloc] init];
        [self presentViewController:creat animated:YES completion:nil];
    }else if(sender.tag == 3){
        //任务档案
        TSFinishTabBarController * creat = [[TSFinishTabBarController alloc] init];
        [self presentViewController:creat animated:YES completion:nil];
    }else if(sender.tag == 4){
        //任务点赞
        TSPraiseTabBarController * creat = [[TSPraiseTabBarController alloc] init];
        [self presentViewController:creat animated:YES completion:nil];
    }
}

-(void)addTopImage{
    topImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"work_top"]];
    [self.view addSubview:topImage];
}

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    topImage.frame =  CGRectMake(0,0,currentDeviceWidth,TOP_IMAGE_HEIGHT);
}
@end
